Skip to content

Add pluggable regex engine support#41

Merged
rayokota merged 10 commits into
masterfrom
regex-option
Jul 5, 2026
Merged

Add pluggable regex engine support#41
rayokota merged 10 commits into
masterfrom
regex-option

Conversation

@rayokota

@rayokota rayokota commented Jul 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a pluggable regex_engine hook so JSONata regex literals can be compiled by an alternative regex backend (e.g., via an adapter to RE2), while keeping the stdlib re behavior as the default.

Changes:

  • Thread a regex_engine parameter from JsonataParserTokenizer to compile regex literals via regex_engine.compile(pattern, flags).
  • Generalize “is regex” checks away from isinstance(x, re.Pattern) to support non-stdlib compiled regex objects.
  • Add an opt-in RE2-focused test suite and a dedicated nox session to run it.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/re2_engine_test.py Adds RE2 adapter + end-to-end tests for regex operations under a pluggable engine.
src/jsonata/tokenizer.py Compiles regex literals using an injected regex_engine instead of hardcoding re.
src/jsonata/signature.py Treats compiled regex values as “function-like” via the new regex predicate.
src/jsonata/parser.py Passes regex_engine into the tokenizer during parse.
src/jsonata/jsonata.py Exposes regex_engine on Jsonata and threads it into parsing; updates regex detection.
src/jsonata/functions.py Uses the new regex predicate; makes $eval preserve the current instance’s regex engine.
noxfile.py Adds a test_re2 session to run the optional RE2 engine tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/re2_engine_test.py Outdated
Comment thread noxfile.py
Comment thread src/jsonata/functions.py
Comment thread src/jsonata/jsonata.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/jsonata/functions.py
Comment thread src/jsonata/functions.py
Comment thread src/jsonata/functions.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

src/jsonata/functions.py:1863

  • Functions.is_regex() is referenced elsewhere (e.g., signature/jsonata) but isn't implemented, which will raise AttributeError at runtime. Also, $assert(false, <message>) currently ignores the provided message, which breaks existing tests and user-facing behavior.
    @staticmethod
    def assert_fn(condition: Optional[bool], message: Optional[str]) -> None:
        if condition is utils.Utils.NULL_VALUE:

src/jsonata/functions.py:481

  • This padding construction uses repeated string concatenation in a loop, which is significantly less efficient than string multiplication for larger pad sizes. Since pad_str is normalized to a non-empty string above, the original multiplication approach is safe here.
        padding = pad_str * (pads // len(pad_str) + 1)
        return Functions.substr(padding, 0, pads) + string

    # Source: Jsonata4Java PadFunction
    @staticmethod

Comment thread src/jsonata/functions.py Outdated
Comment thread src/jsonata/tokenizer.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread tests/re2_engine_test.py Outdated
Comment thread src/jsonata/functions.py Outdated
Comment thread src/jsonata/functions.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread noxfile.py Outdated
Comment thread src/jsonata/functions.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/jsonata/functions.py:2237

  • In function_eval, Jsonata.CURRENT.jsonata is read after constructing the nested Jsonata instance. Since Jsonata.init overwrites the thread-local CURRENT, this can accidentally pass the nested instance’s environment/bindings (and any other CURRENT-derived state) instead of the enclosing expression’s. Capture the enclosing Jsonata before creating the nested one, use it for regex_engine/environment, and restore CURRENT afterwards.
            ast = jsonata.Jsonata(expr, jsonata.Jsonata.CURRENT.jsonata.regex_engine)
        except Exception as err:
            # error parsing the expression passed to $eval
            # populateMessage(err)
            raise jexception.JException("D3120", -1)

Comment thread tests/re2_engine_test.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comment thread src/jsonata/tokenizer.py Outdated
Comment thread src/jsonata/tokenizer.py Outdated
Comment thread src/jsonata/functions.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

@rayokota rayokota merged commit d250b89 into master Jul 5, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants